package com.opengms.HydroModelsIntegration.Controller;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.io.File;

/**
 * @Author: David.Xiao
 * @Date: 2018/12/19 20:33
 * @Description:
 */

@Path("/OutputVisualizationService")
@Produces(MediaType.APPLICATION_XML)
public class OutputVisualizationService {

    @GET
    @Path("?udxId={udxId}")
    public Document getOutputUdx(@PathParam("udxId") String udxId)
    {
        String localUdxPath =this.getClass().getResource("/").getPath()+"\\outputUdxData";
        String udxFileName = localUdxPath +"\\" + udxId + ".xml";

        Document udxDocument = readXml(udxFileName);
        return  udxDocument;

    }

    @GET
    @Path("?schemaName={schemaName}")
    public Document getOutputSchema(@PathParam("schemaName") String schemaName)
    {

        String localSchemaPath =this.getClass().getResource("/").getPath()+"\\outputUdxSchema";
        String schemaFileName = localSchemaPath +"\\" + schemaName + ".xml";

        Document schemaDocument = readXml(schemaFileName);
        return schemaDocument;
    }


    public Document readXml(String fileName)
    {
        Document document = null;
        try {
            File file = new File(fileName);
            SAXReader reader = new SAXReader();
            document= reader.read(file);
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        return document;
    }
}
